package com.example.shopfour.application;


import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.example.shopfour.R;

import java.io.InputStream;
import java.lang.annotation.Retention;
import java.util.ArrayList;
import java.util.Arrays;

public class Goods {
    private ArrayList<Bitmap> bitmaps;
    private String goodsName;
    private String describe;
    private ArrayList<String> tags;
    private int price;

    public static ArrayList<Goods> GOODSLIST =new ArrayList<>();
    public static Goods DEULT_GOODS = new Goods();

    public Goods(){
        this.bitmaps = new ArrayList<>();
        this.goodsName = "";
        this.describe = "";
        this.tags = new ArrayList<>();
        this.price = -1;
    }

    public Goods(String goodsName, String describe, String[] tags, int price){
        this();
        this.goodsName = goodsName;
        this.describe = describe;
        this.price = price;
        this.tags.addAll(Arrays.asList(tags));
    }

    public ArrayList<Bitmap> getBitmaps() {
        return bitmaps;
    }

    public void setBitmaps(ArrayList<Bitmap>  bitmaps) {
        this.bitmaps = bitmaps;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }

    public ArrayList<String> getTags() {
        return tags;
    }

    public void setTags(ArrayList<String> tags) {
        this.tags = tags;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public boolean equals(Goods goods){
        return this.getGoodsName().equals(goods.getGoodsName())
                && this.getTags().equals(goods.getTags())
                && this.getDescribe().equals(goods.getDescribe())
                && this.getPrice() == goods.getPrice();
    }

    public static String toPriceString(int price){
        StringBuffer sb = new StringBuffer(String.valueOf(price));
        //小于2位数
        if (sb.length()<=2)
        {
            if (sb.length() == 0){
                sb.insert(0,"0.00");
            } else if(sb.length() == 1){
                sb.insert(0,"0.0");
            } else if(sb.length() == 2){
                sb.insert(0,"0.");
            }
        } else {
            sb.insert(sb.length()-2,'.');
        }
        return sb.toString();
    }

    public static void getDefaultGoodsList(Context context){

        GOODSLIST.clear();
        Goods goods1 = new Goods("蔚来汽车屏幕钢化膜","高清高透/专车专用/不粘指纹",new String[]{"汽车配件","钢化膜"},5000);
        goods1.setDescribe("触摸灵敏，轻松滑屏，高精度玻璃切割技术，超薄，超顺，超灵敏");
        Goods goods2 = new Goods("蔚来汽车钥匙扣","蔚来系列专用 适用ES8 ET7等车型",new String[]{"汽车配件","钥匙扣"},3500);
        goods2.setDescribe("蔚来系列汽车钥匙专用 钥匙A适用于19-22款ES6 18-22款ES8 20-22款EC6，钥匙B适用于22款ET7 22款ES7 22款ETS");
        Goods goods3 = new Goods("蔚来nomi草帽装饰","简约时尚/独特风格/贴合机身",new String[]{"汽车配件","nomi配饰"},1500);
        goods3.setDescribe("带上帽子后萌趣感+1，简易安装，自己动手");
        Goods goods4 = new Goods("蔚来枕头人体工学奢侈级","美潮标杆/舒享驾乘",new String[]{"汽车配件","枕头"},18000);
        goods4.setDescribe("软糯支撑，横扫疲劳，既能护颈，也能纠正坐姿。重新定义汽车护颈枕功能属性。");

        ArrayList<Bitmap> bitmaps1 = new ArrayList<>();
        bitmaps1.add(BitmapFactory.decodeResource(context.getResources(), R.drawable.mo_picture));
        goods1.setBitmaps(bitmaps1);

        ArrayList<Bitmap> bitmaps2 = new ArrayList<>();
        bitmaps2.add(BitmapFactory.decodeResource(context.getResources(), R.drawable.key_picture));
        goods2.setBitmaps(bitmaps2);

        ArrayList<Bitmap> bitmaps3 = new ArrayList<>();
        bitmaps3.add(BitmapFactory.decodeResource(context.getResources(), R.drawable.heat_picture));
        goods3.setBitmaps(bitmaps3);

        ArrayList<Bitmap> bitmaps4 = new ArrayList<>();
        bitmaps4.add(BitmapFactory.decodeResource(context.getResources(), R.drawable.pillow_picture));
        goods4.setBitmaps(bitmaps4);


        GOODSLIST.add(goods1);
        GOODSLIST.add(goods2);
        GOODSLIST.add(goods3);
        GOODSLIST.add(goods4);
    }

}
